Public Class Form1 Inherits System.Windows.Forms.Form Dim outp As IO.StreamWriter Dim inp1 As IO.StreamReader #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents lstCopy As System.Windows.Forms.ListBox Private Sub InitializeComponent() Me.lstCopy = New System.Windows.Forms.ListBox Me.SuspendLayout() ' 'lstCopy ' Me.lstCopy.Location = New System.Drawing.Point(32, 16) Me.lstCopy.Name = "lstCopy" Me.lstCopy.Size = New System.Drawing.Size(312, 238) Me.lstCopy.TabIndex = 0 ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(432, 465) Me.Controls.Add(Me.lstCopy) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim cnt As Integer Dim strLine As String If Not IO.File.Exists("somejunk.txt") Then outp = IO.File.CreateText("somejunk.txt") For cnt = 1 To 100 outp.Write(cnt.ToString.PadLeft(5)) ' pad left helps to put things in columns outp.WriteLine((" " & cnt ^ 2).PadLeft(7)) Next cnt outp.Close() Else MsgBox("oops, file already exists") outp = IO.File.AppendText("somejunk.txt") For cnt = 101 To 200 outp.Write(cnt.ToString.PadLeft(5)) ' pad left helps to put things in columns outp.WriteLine((" " & cnt ^ 2).PadLeft(7)) Next cnt outp.Close() End If ' either way, the file exists now inp1 = IO.File.OpenText("somejunk.txt") Do Until inp1.Peek() = -1 ' end of file strLine = inp1.ReadLine() lstCopy.Items.Add(strLine) Loop inp1.Close() lstCopy.SelectedIndex = 0 ' default the selection to the first item End Sub Private Sub lstCopy_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstCopy.SelectedIndexChanged Dim strLine As String strLine = lstCopy.SelectedItem strLine = strLine.Trim Dim num As Integer Dim sq As Integer Dim blankpos As Integer = strLine.IndexOf(" "c) num = Convert.ToInt32(strLine.Substring(0, blankpos)) sq = Convert.ToInt32(strLine.Substring(blankpos).Trim()) Dim cube As Integer = num * sq MsgBox(num & " squared is: " & sq & " and cubed is: " & cube) End Sub End Class